package com.threeox.commonlibrary.entity.engine.event;

import com.threeox.commonlibrary.entity.base.BaseObj;
import com.threeox.commonlibrary.entity.engine.request.RequestMsg;
import com.threeox.commonlibrary.entity.engine.verify.VerifyMsg;
import com.threeox.utillibrary.util.EmptyUtils;
import com.threeox.utillibrary.util.res.StringHelper;

import java.util.List;

/**
 *
 * @ClassName: BaseEventMessage
 *
 * @Description: TODO(基本的EventMessage)
 *
 * @author 赵屈犇
 *
 * @date 创建时间: 2017/7/11 11:16
 *
 * @version 1.0
 *
 */
public class BaseEventMessage extends BaseObj {

    private String loadText;// 响应事件时dialog的展示
    private RequestMsg requestMsg;// 请求对象
    private ActivityMsg activityMsg;// Activity 对象
    private List<VerifyMsg> verifyMsgs;// 校验信息对象
    private List<BroadCastMessage> broadCastMsgs;// 广播通知的对象集合 在响应事件完成时调用

    private boolean isVerify = true;// 是否开启校验
    private boolean isFinish = false;// 是否在响应完成之后关闭  默认不关闭
    private boolean isCancelable = true;// dialog弹出后会点击屏幕或物理返回键，dialog是否消失 默认消失
    private boolean isCanceledTouch = true;// dialog弹出后会点击屏幕，dialog是否消失 默认消失
    private boolean isCopyContent = false;// 是否复制内容，如果是TextView的

    public void initData(StringHelper stringHelper) {
        if (EmptyUtils.isEmpty(loadText)) {
            this.loadText = "正在请求...";
        } else {
            String loadMessage = stringHelper.getString(loadText);
            if (EmptyUtils.isNotEmpty(loadMessage)) {
                this.loadText = loadMessage;
            }
        }
        if (requestMsg != null) {
            requestMsg.initData(stringHelper);
        }
        if (activityMsg != null) {
            activityMsg.initData(stringHelper);
        }
        if (EmptyUtils.isNotEmpty(verifyMsgs)) {
            for (VerifyMsg verifyMessage: verifyMsgs) {
                verifyMessage.initData(stringHelper);
            }
        }
        if (EmptyUtils.isNotEmpty(broadCastMsgs)) {
            for (BroadCastMessage broadCastMessage: broadCastMsgs) {
                broadCastMessage.initData(stringHelper);
            }
        }
    }

    public String getLoadText() {
        return loadText;
    }

    public void setLoadText(String loadText) {
        this.loadText = loadText;
    }

    public RequestMsg getRequestMsg() {
        return requestMsg;
    }

    public void setRequestMsg(RequestMsg requestMsg) {
        this.requestMsg = requestMsg;
    }

    public ActivityMsg getActivityMsg() {
        return activityMsg;
    }

    public void setActivityMsg(ActivityMsg activityMsg) {
        this.activityMsg = activityMsg;
    }

    public List<VerifyMsg> getVerifyMsgs() {
        return verifyMsgs;
    }

    public void setVerifyMsgs(List<VerifyMsg> verifyMsgs) {
        this.verifyMsgs = verifyMsgs;
    }

    public List<BroadCastMessage> getBroadCastMsgs() {
        return broadCastMsgs;
    }

    public void setBroadCastMsgs(List<BroadCastMessage> broadCastMsgs) {
        this.broadCastMsgs = broadCastMsgs;
    }

    public boolean isVerify() {
        return isVerify;
    }

    public void setIsVerify(boolean verify) {
        isVerify = verify;
    }

    public boolean getIsFinish() {
        return isFinish;
    }

    public void setIsFinish(boolean finish) {
        isFinish = finish;
    }

    public boolean isCancelable() {
        return isCancelable;
    }

    public void setIsCancelable(boolean cancelable) {
        isCancelable = cancelable;
    }

    public boolean isCanceledTouch() {
        return isCanceledTouch;
    }

    public void setIsCanceledTouch(boolean canceledTouch) {
        isCanceledTouch = canceledTouch;
    }

    public boolean isCopyContent() {
        return isCopyContent;
    }

    public void setIsCopyContent(boolean copyContent) {
        isCopyContent = copyContent;
    }

    /**
     * 初始化所有的参数
     *
     * @param intent
     *
     * public void initAllParams(Intent intent) {
     *  if (null != requestMsg)
     *      requestMsg.initAllParams(intent);
     *  if (null != activityMsg)
     *      activityMsg.initParam(intent);
     * }
     */

    /**
     * 初始化所有的参数
     *
     * @param data
     */
    public void initAllParams(Object data) {
        if (null != requestMsg)
            requestMsg.initAllParams(data);
        if (null != activityMsg)
            activityMsg.initParam(data);
        if (EmptyUtils.isNotEmpty(broadCastMsgs)) {
            for (BroadCastMessage broadCastMessage: broadCastMsgs) {
                broadCastMessage.initParam(data);
            }
        }
    }

    /**
     * 初始化请求参数
     *
     * @param data
     *
     * public void initRequestParams(Object data) {
     *  if (null != requestMsg) {
     *      requestMsg.initRequestParam(data);
     *      requestMsg.initRequestParam(data);
     *  }
     * }
     */

}
